package com.example.sjjg.utest

import com.example.sjjg.utest.app.Test1
import org.junit.Test

import org.junit.Assert.*
import org.junit.Ignore
import org.junit.experimental.categories.Categories
import org.junit.experimental.categories.Category
import org.junit.runner.Description
import org.junit.runner.RunWith
import org.junit.runner.Runner
import org.junit.runner.notification.RunNotifier
import org.junit.runners.BlockJUnit4ClassRunner
import org.junit.runners.Suite




/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */


class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }
    @Test
    fun test1_gt(){
        val x = 1
        val y = 100
        val test = Test1()

        assertTrue("failure - x greater than y",test.gt(y,x))
        assertFalse("failure - x not greater than y",test.lt(x,y))
    }

    @Test
    fun test2_say(){
//        val activity: Activity = Robolectric.setupActivity(MyActivity::class.java)
    }

    @Test(timeout = 3000)
    fun test_timeout(){
        var time = 1
        while (time++ < 5){
            println("time = $time")
            Thread.sleep(1000 * 1)
        }
        println("test_timeout finished")
    }

    @Ignore("Test is ignored as a demonstration")
    @Test
    fun test_ignore(){
        println("test_ignore")
    }

    class RunnerA : Runner(){
        @Test
        fun f1(){
            println("RunnerA . f1")
        }
        @Test
        fun f2(){
            println("RunnerA . f2")
        }
        @Test
        fun f3(){
            println("RunnerA . f3")
        }
        @Ignore("RunnerA")
        @Test
        fun f4(){
            println("RunnerA . f4")
        }

        override fun getDescription(): Description {
            TODO("Not yet implemented")
            println("RunnerA . getDescription")
        }

        override fun run(notifier: RunNotifier?) {
            println("RunnerA . run")
        }
    }

    @RunWith(BlockJUnit4ClassRunner::class)
    class TestB{
        @Test
        fun testB_f1(){
            println("testB . f1")
        }
    }
    class Suite1{
        @Test
        fun f1(){
            println("Suite1 . f1")
        }
        @Test
        fun f2(){
            println("Suite1 . f2")
        }
        @Ignore("todo")
        @Test
        fun f3(){
            println("Suite1 . ignore f3")
        }
    }

    class Suite2{
        @Test
        fun f1(){
            println("Suite2 . f1")
        }
        @Test
        fun f2(){
            println("Suite2 . f2")
        }
        @Test
        fun f3(){
            println("Suite2 . f3")
        }
    }

    @RunWith(Suite::class)
    @Suite.SuiteClasses(Suite1::class,Suite2::class)
    class TestC{
        @Test
        fun test_runwith(){
            println("TestC . test_runwith")
        }
    }


    //Category
    interface Category1
    interface Category2

    class A{
        @Test
        fun a() {
            println("A.a()")
        }
        @Category(Category2::class)                 //Category2
        @Test
        fun b() {
            println("A.b()")
        }
    }

    @Category(Category1::class,Category2::class)    //Category1,Category2
    class B{
        @Test
        fun c() {
            println("B.c()")
        }
    }

    @Test
    @Category(Category1::class,Category2::class)
    fun test_Category(){

    }

    @RunWith(Categories::class)
    @Categories.IncludeCategory(Category1::class)
    @Suite.SuiteClasses(A::class,B::class)
    class CategoryInclude{
        @Test
        fun main(){
            println("CategoryInclude")
        }
    }

    @RunWith(Categories::class)
    @Categories.ExcludeCategory(Category2::class)
    @Suite.SuiteClasses(A::class,B::class)
    class CategoryExclude{
        @Test
        fun main(){
            println("CategoryExclude")
        }
    }

}